﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;

namespace docExplorer
{
    public partial class rbbDocExplorer : OfficeRibbon
    {
        public rbbDocExplorer()
        {
            InitializeComponent();
        }

        private void rbbDocExplorer_Load(object sender, RibbonUIEventArgs e)
        {

        }

        private void btnExplorer_Click(object sender, RibbonControlEventArgs e)
        {
            if (!btnExplorer.Checked)
            {
                try
                {
                    Globals.ThisAddIn.CustomTaskPanes.Remove(Globals.ThisAddIn.ExplorerCTP);
                }
                catch (Exception)
                {
                    Globals.ThisAddIn.ExplorerCTP = Globals.ThisAddIn.CustomTaskPanes.Add(new uc_Explorer(), "Explorer");
                    Globals.ThisAddIn.ExplorerCTP.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionLeft;
                    Globals.ThisAddIn.ExplorerCTP.Width = 315;
                    Globals.ThisAddIn.ExplorerCTP.Visible = true;

                    Globals.ThisAddIn.ExplorerCTP.VisibleChanged += new EventHandler(ExplorerCTP_VisibleChanged);

                    btnExplorer.Checked = true;
                }
            }
            else
            {
                Globals.ThisAddIn.ExplorerCTP = Globals.ThisAddIn.CustomTaskPanes.Add(new uc_Explorer(), "Explorer");
                Globals.ThisAddIn.ExplorerCTP.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionLeft;
                Globals.ThisAddIn.ExplorerCTP.Width = 315;
                Globals.ThisAddIn.ExplorerCTP.Visible = true;

                Globals.ThisAddIn.ExplorerCTP.VisibleChanged += new EventHandler(ExplorerCTP_VisibleChanged);
            }
        }

        private void ExplorerCTP_VisibleChanged(object sender, EventArgs e)
        {
            btnExplorer.Checked = Globals.ThisAddIn.ExplorerCTP.Visible;
        }

        private void btnSearch_Click(object sender, RibbonControlEventArgs e)
        {
            if (!btnExplorer.Checked)
            {
                try
                {
                    Globals.ThisAddIn.CustomTaskPanes.Remove(Globals.ThisAddIn.SearchCTP);
                }
                catch (Exception)
                {
                    Globals.ThisAddIn.SearchCTP = Globals.ThisAddIn.CustomTaskPanes.Add(new uc_Search(), "Search a Document");
                    Globals.ThisAddIn.SearchCTP.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionLeft;
                    Globals.ThisAddIn.SearchCTP.Width = 315;
                    Globals.ThisAddIn.SearchCTP.Visible = true;

                    Globals.ThisAddIn.SearchCTP.VisibleChanged += new EventHandler(SearchCTP_VisibleChanged);

                    btnSearch.Checked = true;
                }
            }
            else
            {
                Globals.ThisAddIn.SearchCTP = Globals.ThisAddIn.CustomTaskPanes.Add(new uc_Search(), "Search a Document");
                Globals.ThisAddIn.SearchCTP.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionLeft;
                Globals.ThisAddIn.SearchCTP.Width = 315;
                Globals.ThisAddIn.SearchCTP.Visible = true;

                Globals.ThisAddIn.SearchCTP.VisibleChanged += new EventHandler(SearchCTP_VisibleChanged);
            }
        }

        private void SearchCTP_VisibleChanged(object sender, EventArgs e)
        {
            btnSearch.Checked = Globals.ThisAddIn.SearchCTP.Visible;
        }
    }
}
